package com.smartj.web;

import lombok.SneakyThrows;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.core.env.Environment;

import java.net.InetAddress;


@SpringBootApplication(scanBasePackages = {"com.smartj.autowire", "com.smartj.web"})
public class SmartWebApplication {
    private static final Logger LOG = LoggerFactory.getLogger(SmartWebApplication.class);

    public static void main(String[] args) {
        showEnv(SpringApplication.run(SmartWebApplication.class, args));
    }

    @SneakyThrows
    private static void showEnv(ConfigurableApplicationContext application) {
        Environment env = application.getEnvironment();
        String ip = InetAddress.getLocalHost().getHostAddress();
        String port = env.getProperty("server.port");
        String path = env.getProperty("server.servlet.context-path");
        LOG.info("\n-----------------------------------------------------\n" +
                "Application chat-service is running! Access URLs:\n" +
                String.format("Local: \t\t http://localhost:%s%s\n", port, path) +
                String.format("External:\t http://%s:%s%s\n", ip, port, path) +
                "-----------------------------------------------------");
    }
}
